package com.cwnu.controller;

import com.cwnu.entity.Address;
import com.cwnu.result.R;
import com.cwnu.service.AddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * @ProjectName: mall-cwnu
 * @Titile: AddressController
 * @Author: Lucky
 * @Description: 地址控api
 */
@RestController //返回数据
@RequestMapping("address")
@Slf4j
public class AddressController {
    @Autowired
    private AddressService addressService;
    @GetMapping("province")
    public R getAllProvince(){
        List<Address> provinces = addressService.getAllProvince();
        log.info("获取省份信息:{}",provinces);
        return R.ok().data("provinces", provinces);
    }
    //    /address/1001
    @GetMapping("city/{addressRegionId}")
    public R getAddressList(@PathVariable("addressRegionId") Integer addressRegionId ){
        //断言
        Assert.notNull(addressService,"地址所属地编号不能为空");
        log.info("根据所属地id：{}查询",addressRegionId);
        List<Address> addressList = addressService.getAddressList(addressRegionId);
        log.info("获取地址信息:{}",addressList);
        return R.ok().data("addressList", addressList);
    }
}
